<?php
class TourLocation extends TourLocationPeer
{
	function TourLocation()
	{
		parent::TourLocationPeer();
	}
	
	
	public static function retriveByTourAndLocation($tour_id, $location_id)
	{
		$db = new Database();
		$query = "SELECT id FROM tour_location WHERE tour_id = ".$tour_id." AND location_id = ".$location_id;
		$result = $db->query($query);
		$id = $db->result;
		$id = mysql_fetch_row($id);
		if (isset($id[0])) {
			$id = $id[0];
			$tour_location = new TourLocation();
			$tour_location->select($id);
			return $tour_location;
		}
		return null;
	}
	
	
	public static function getCurrentIndex($tour_id)
	{
		$db = new Database();
		$query = "SELECT max(location_index) FROM tour_location WHERE tour_id = ".$tour_id;
		$result = $db->query($query);
		$max_index = $db->result;
		$max_index = mysql_fetch_row($max_index);
		return isset($max_index[0]) ? $max_index[0] : 0;
	}
}
?>